// pages/my_center_new/my_center_new.js
const app = getApp();
var router = require("../../router.js");
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    //功能列表
    list: [{
        src: "../../image/list_1.png",
        name: "我的保险",
        path: "../mysafe/mysafe"
      },
      {
        src: "../../image/list_2.png",
        name: "我的收入",
        path: "../mysale/mysale"
      },
      {
        src: "../../image/list_3.png",
        name: "我的报名",
        path: "../my_bm/my_bm"
      },
      // {
      //   src: "../../image/list_4.png",
      //   name: "卡包",
      //   path: "../mycard/mycard"
      // },
      // {
      //   src: "../../image/list_5.png",
      //   name: "我的课程",
      //   path: "../mycourse/mycourse"
      // },
      {
        src: "../../image/list_9.png",
        name: "资料编辑",
        path: "../edit_user_info/edit_user_info"
      },
      {
        src: "../../image/list_10.png",
        name: "客服",
        path: "phone"
      },

    ],
    // 会员等级列表
    gradeList: [
      '普通会员',
      'VIP会员',
      '黄金VIP会员'
    ],

  },

  /**
   * 组件的方法列表
   */
  methods: {
    go_vip(e) {
      let index = e.currentTarget.dataset.index;
      wx.navigateTo({
        url: '../to_vip/to_vip?type=' + index,
      })
    },
    topage(e) {
      let path = e.currentTarget.dataset.path;
      if (path == 'phone') {
        wx.makePhoneCall({
          phoneNumber: '40088880088' //仅为示例，并非真实的电话号码
        })
        return;
      }
      app.navTo(path)
    },
  },
  attached() {
    console.log("my_center_init");
    app.isLogin();
    var that = this;
    app.request({
      url: router.user.info,
      method: "POST",
      data: {
        userId: wx.getStorageSync('userInfo')['id']
      },
      success: function(data) {
        wx.setStorageSync('grade', data.user_list.grade)
        that.setData({
          name: data.user_list.nickname,
          icon: data.user_list.head,
          grade: data.user_list.grade,
        });
      }
    })
  }
})